package com.example.task1.ui.AllService.YouthStation;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.StationBean;
import com.example.task1.ui.BaseAdapter;

import java.util.List;

public class StationAdapter extends BaseAdapter<StationBean.RowsDTO> {
    private ImageView image;
    private TextView tvTitle;
    private TextView tvNNum;
    private TextView tvVNum;
    private TextView tvPhone;
    private TextView tvTime;
    private TextView tvAddress;
    private Context context;

    public StationAdapter(Context context) {
        this.context = context;
    }

    private List<StationBean.RowsDTO> data;

    public void setData(List<StationBean.RowsDTO> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    protected int getLayout() {
        return R.layout.stationlayout;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<StationBean.RowsDTO> getData() {
        return data;
    }

    @Override
    protected void onBind(myHolder holder, StationBean.RowsDTO date) {
        MyApplication.glide(image, date.getCoverImgUrl());
        tvTitle.setText(date.getName());
        tvAddress.setText("地址：" + date.getAddress());
        tvPhone.setText("联系方式：" + date.getPhone());
        tvTime.setText("营业时间：" + date.getWorkTime());
        tvNNum.setText("剩余男床位：：" + date.getBedsCountBoy());
        tvVNum.setText("剩余女床位：" + date.getBedsCountGirl());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,StationDetailsActivity.class);
                intent.putExtra("id",date.getId());
                context.startActivity(intent);
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View itemView) {
        image = (ImageView) itemView.findViewById(R.id.image);
        tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
        tvNNum = (TextView) itemView.findViewById(R.id.tv_nNum);
        tvVNum = (TextView) itemView.findViewById(R.id.tv_vNum);
        tvPhone = (TextView) itemView.findViewById(R.id.tv_phone);
        tvTime = (TextView) itemView.findViewById(R.id.tv_time);
        tvAddress = (TextView) itemView.findViewById(R.id.tv_address);
    }
}
